import DictAPI, { DictAllData, DictAllDataItem, DictItem } from "@/api/dict";

export const useDictDataStore = defineStore("dictData", () => {
  const dictData = ref<DictAllData>();

  const getDictDataApi = async () => {
    // 请求api数据

    const res = await DictAPI.getAllData();
    console.log(res, "DictAPI.getAllData");
    dictData.value = res;
  };

  /**
   *
   * @param code 字典的code eg:"gender"
   * @param key 字典项键
   * @returns 字典项值
   */
  const getDictItemVal = (code: string, key: string) => {
    return dictData.value![code].keyVal[key];
  };

  // 把需要调用的函数和值返回
  return {
    getDictDataApi,
    getDictItemVal,
  };
});
